package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.mapper.DepartmentMapper;
import com.zhentao.mapper.DepartmentSonMapper;
import com.zhentao.mapper.HospitalMapper;
import com.zhentao.pojo.DepartmentSon;
import com.zhentao.pojo.Doctor;
import com.zhentao.pojo.Hospital;
import com.zhentao.service.DepartmentSonService;
import com.zhentao.service.DoctorService;
import com.zhentao.mapper.DoctorMapper;
import com.zhentao.service.HospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author HP
 * @description 针对表【doctor】的数据库操作Service实现
 * @createDate 2025-03-21 16:04:06
 */
@Service
public class DoctorServiceImpl extends ServiceImpl<DoctorMapper, Doctor>
        implements DoctorService {

    @Autowired
    private DoctorMapper doctorMapper;
    @Autowired
    private DepartmentSonMapper departmentSonMapper;
    @Autowired
    private HospitalMapper hospitalMapper;

    @Override
    public List<Doctor> getTypeById(Integer id) {
        QueryWrapper<Doctor> wrapper = new QueryWrapper<>();
        wrapper.eq("deid", id);
        List<Doctor> doctors = doctorMapper.selectList(wrapper);
        for (Doctor doctor : doctors) {
            DepartmentSon deSon = departmentSonMapper.selectById(doctor.getDeid());
            Hospital hospital = hospitalMapper.selectById(doctor.getHid());
            doctor.setDepartmentName(deSon.getDname());
            doctor.setHospitalName(hospital.getHname());
            doctor.setHospitalPhone(hospital.getPhone());
            doctor.setHospitalAddress(hospital.getAddress());
            doctor.setHospitalPing(hospital.getPing());
        }
        return doctors;
    }

    @Override
    public Doctor findByDid(Integer did) {
        Doctor doctor = doctorMapper.selectById(did);
        DepartmentSon deSon = departmentSonMapper.selectById(doctor.getDeid());
        Hospital hospital = hospitalMapper.selectById(doctor.getHid());
        doctor.setDepartmentName(deSon.getDname());
        doctor.setHospitalName(hospital.getHname());
        doctor.setHospitalPhone(hospital.getPhone());
        doctor.setHospitalAddress(hospital.getAddress());
        doctor.setHospitalPing(hospital.getPing());
        return doctor;
    }
}




